﻿using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace DualityEngine.Business
{
    public class ChatManager
    {
        private static readonly ChatManager instance = new ChatManager();
        private Queue<string> messages;
        KeyboardState currentKeyboardState;

        string textString = "";

        public static ChatManager Instance
        {
            get
            {
                return instance;
            }
        }

        private ChatManager()
        {
            messages = new Queue<string>();
        }

        public void AddMessage(string message)
        {
            if (messages.Count == 20)
                messages.Dequeue();
            messages.Enqueue(message);
        }

        public void Update(GameTime gameTime)
        {
            KeyboardState oldKeyboardState = currentKeyboardState;
            currentKeyboardState = Keyboard.GetState();
        }

        public void Draw(GameTime gameTime)
        {
            int counter = 1;
            foreach (string s in messages)
            {
                if (s.Contains("Console say:"))
                    ResourceManager.Instance.spriteBatch.DrawString(ResourceManager.Instance.kootenay, s, new Vector2(0, 100 + (counter * 15)), Color.Yellow);
                else
                    ResourceManager.Instance.spriteBatch.DrawString(ResourceManager.Instance.kootenay, s, new Vector2(0, 100 + (counter * 15)), Color.White);
                counter++;
            }
            ResourceManager.Instance.spriteBatch.DrawString(ResourceManager.Instance.kootenay, textString, new Vector2(600, 100), Color.White);
        }
    }
}
